package com.micro.service.controller;

import com.micro.service.annotation.ApiVersion;
import com.micro.service.entity.ResponseMessage;
import com.micro.service.model.UserInfo;
import com.micro.service.rpc.RpcUserInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * Create by Vic Xu on 2019/3/19
 */
@RestController
@ApiVersion(1)
@RequestMapping("{version}/user")
public class UserInfoController {

    @Autowired
    private RpcUserInfo rpcUserInfo;

    @GetMapping(produces = {"application/json;charset=UTF-8"})
    public ResponseMessage<List<UserInfo>> getUserInfo() {
        return rpcUserInfo.getUserInfo();
    }

    @PostMapping(produces = {"application/json;charset=UTF-8"})
    public ResponseMessage<UserInfo> saveUserInfo(@RequestBody UserInfo userInfo) {
        return rpcUserInfo.saveUserInfo(userInfo);
    }

    @PostMapping(value = "list", produces = {"application/json;charset=UTF-8"})
    public ResponseMessage<Integer> batchSaveUserInfo(@RequestBody List<UserInfo> userInfos) {
        return rpcUserInfo.batchSaveUserInfo(userInfos);
    }

    @PutMapping(produces = {"application/json;charset=UTF-8"})
    public ResponseMessage<UserInfo> updateUser(@RequestBody UserInfo userInfo) {
        return rpcUserInfo.updateUser(userInfo);
    }

    @DeleteMapping(value = "{id}")
    public ResponseMessage<Integer> deleteUser(@PathVariable("id") String id) {
        return rpcUserInfo.deleteUser(id);
    }

}
